/**
 * Meituan.com Inc.
 * Copyright (c) 2010-2019 All Rights Reserved.
 */
package com.tuyou.springboot.configuration.controller;

import com.tuyou.springboot.configuration.po.PropertiesPo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p></p>
 *
 * @author tuyou@meituan.com
 * @version v0.1 2019-01-30 5:59 PM tuyou Exp $$
 */
@PropertySource("classpath:another.properties")
@RestController
public class HelloController {

    @Value("${name}")
    String name;

    @Value("${profile}")
    String profile;

    @Autowired
    PropertiesPo po;

    @GetMapping("/hello")
    public String hello(HttpServletResponse response) {
//        try {
//            response.sendRedirect("http://localhost:8000/redirect");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
        return "hello page";
    }

    @GetMapping("/hello2")
    public void hello2(HttpServletResponse response) {
        try {
            response.sendRedirect("http://localhost:8000/redirect");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @GetMapping("/redirect")
    public String redirect() {
        return "redirect page";
    }

    @GetMapping("/name")
    public String getName() {
        return name;
    }

    @GetMapping("/profile")
    public String getProfile() {
        return profile;
    }

    @GetMapping("/po")
    public String po() {
//        System.out.println("2222222222222");
        return po.toString();
//        return "123";
    }
}